// 整数
const InterNum = (rule, value, callback) => {
  const reg = /^[0-9]*[1-9][0-9]*$/
  if (!value) {
    return false
  } else if (!reg.test(value)) {
    return false
  } else {
    callback()
  }
}

// 正整数
const positiveIntegers = (rule, value, callback) => {
  const reg = /[1-9]\d*/
  if (!value) {
    return callback(new Error('请填写正整数'))
  } else if (!reg.test(value)) {
    return callback(new Error('请输入正整数'))
  } else {
    callback()
  }
}

// 纳税人识别号
const invoiceTaxpayerNumber = (rule, value, callback) => {
  const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{20}([\x00-\xff]+)$)/;
  if (!value) {
    return callback(new Error('纳税人识别号不能为空'))
  } else if (!reg.test(value)) {
    return callback(new Error('请输入正确的纳税人识别号'))
  } else {
    callback()
  }
}

// 价格
const price = (rule, value, callback) => {
  if (!value < 0) {
    return callback(new Error('请输入正确的价格'))
  } else {
    callback()
  }
}
// 营业执照号
const businessNum = (rule, value, callback) => {
  const reg = /^(?:(?![IOZSV])[\dA-Z]){2}\d{6}(?:(?![IOZSV])[\dA-Z]){10}$/
  if (value == null) {
    return callback(new Error('营业执照号不能为空'))
  } else if (!reg.test(value)) {
    return callback(new Error('请输入正确的营业执照号'))
  } else {
    callback()
  }
}

// 手机号码
const phone = (value) => {
  const reg = /^(1[0-9][0-9])\d{8}$/
  if (!reg.test(value)) {
    return false
  } else {
    return true
  }
}
// 邮箱
const email = (value) =>{
  var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
  if (!reg.test(value)) {
    return false
  } else {
    return true
  }
}
// 密码
// const password = (value) => {
//   const reg = /^[\w]{6,12}$/
//   if (!reg.test(value)) {
//     return false
//   } else {
//     return true
//   }
// }
const password = (value) => {
  const reg = /^[a-z0-9]{6,16}$/;
  if (!reg.test(value)) {
    return false
  } else {
    return true
  }
}


// 固话和手机号码
const phoneCall = (rule, value, callback) => {
  const reg = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$|^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$|^0\d{2,3}-?\d{7,8}$/;
  if (!reg.test(value)) {
    return callback(new Error('请输入正确的联系方式'))
  } else {
    callback()
  }
}
const postalcode = (rule, value, callback) => {
  const reg = /^[1-9]\d{5}$/
  if (!reg.test(value)) {
    return callback(new Error('请输入正确的邮政编码'))
  } else {
    callback()
  }
}

// 银行卡
const creditcard = (rule, value, callback) => {
  const reg = /^([1-9]{1})(\d{14}|\d{16}|\d{18})$/
  if (!reg.test(value)) {
    return callback(new Error('请输入正确的银行卡'))
  } else {
    callback()
  }
}

// 身份证
const idcard = (value) => {
  const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  if (!reg.test(value)) {
    return false
  } else {
    return true
  }
}
//6-18位字母和数字的混合组成
const mixez = (rule, value, callback) => {
  const reg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,18}$/
  if (!reg.test(value)) {
    return callback(new Error('必须是6-18的英文+数字组合'))
  } else {
    callback()
  }
}

//资质证书表单验证--图片
const validateCertificateListImage = (rule, value, callback) => {
  const _validate = value.qualificationUrl;
  console.log(_validate)
  if (_validate === undefined || _validate === '') {
    callback(new Error('请选择该资质的图片'));
  } else {
    callback()
  }
}

//资质证书表单验证--证书号
const validateCertificateListNumber = (rule, value, callback) => {
  const reg = /^[a-zA-Z0-9]+$/
  const _validate = value.qualificationNum;

  if (_validate === undefined || _validate === '') {
    callback(new Error('请输入证件号'));
  } else if (_validate == null) {
    callback()
  } else if (_validate != null && !reg.test(_validate)) {
    callback(new Error('请输入正确的证件号'));
  } else {
    callback()
  }
}

//资质证书表单验证--开始日期
const validateCertificateListTimeStart = (rule, value, callback) => {
  const _validate = value.qualificationStartTime;
  if (value.qualificationLongEffective === 0 &&
    (_validate === undefined || _validate === '' || _validate === null)
  ) {
    callback(new Error('请选择资质的开始日期'));
  } else {
    callback()
  }
}

//资质证书表单验证--结束日期
const validateCertificateListTimeEnd = (rule, value, callback) => {
  const _validate = value.qualificationEndTime;
  if (value.qualificationLongEffective === 0 &&
    (_validate === undefined || _validate === '' || _validate === null)
  ) {
    callback(new Error('请选择资质的结束日期'));
  } else {
    callback()
  }
}


export default {
  InterNum,
  positiveIntegers,
  price,
  phone,
  email,
  password,
  phoneCall,
  postalcode,
  creditcard,
  idcard,
  mixez,
  businessNum,
  invoiceTaxpayerNumber,
  // comfimpwd,
  validateCertificateList: {
    image: validateCertificateListImage,
    number: validateCertificateListNumber,
    startTime: validateCertificateListTimeStart,
    endTime: validateCertificateListTimeEnd
  }
}
